package jus.aor.mobilagent.kernel;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;

public class AgentInputStream extends ObjectInputStream {
	
	private ClassLoader loader;
	private AgentServer agentServer;

	public AgentInputStream(ClassLoader loader,AgentServer agentServer,InputStream is) throws IOException{
		super(is);
		
		this.loader = loader;
		this.agentServer = agentServer;
	}
	
	public Agent readAgent() throws ClassNotFoundException, IOException{
		Jar j = (Jar)this.readObject();
		BAMLoader l = new BAMLoader(loader);
		l.intergrecode(j);
		Agent a = (Agent)this.readObject();
		a.init(l, agentServer, agentServer.getNameServer());
		return a;
	}
}
